package com.stroke.tools.animation;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

/**
 * Author: Igor Bubelov
 * Date: 3/8/11 3:22 PM
 */
public class MainScreen extends JFrame implements Screen {
    private Map<String, Component> components = new HashMap<String, Component>();

    public MainScreen() throws HeadlessException {
        initUI();

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Controller controller = new MainScreenController(this);
    }

    private void initUI() {
        FrameList frameList = new FrameList();
        components.put("FrameList", frameList);

        JLabel imageLabel = new JLabel();
        components.put("ImageLabel", imageLabel);

        JButton moveUpButton = new JButton("↑");
        components.put("MoveUpButton", moveUpButton);

        JButton moveDownButton = new JButton("↓");
        components.put("MoveDownButton", moveDownButton);

        JButton addFrameButton = new JButton("+");
        components.put("AddFrameButton", addFrameButton);

        JButton removeFrameButton = new JButton("-");
        components.put("RemoveFrameButton", removeFrameButton);

        JButton loadButton = new JButton("Load");
        components.put("LoadButton", loadButton);

        JButton saveButton = new JButton("Save");
        components.put("SaveButton", saveButton);

        JButton exitButton = new JButton("Exit");
        components.put("ExitButton", exitButton);

        JScrollPane frameListScrollPane = new JScrollPane(frameList);
        frameListScrollPane.setPreferredSize(new Dimension(100, 280));

        imageLabel.setPreferredSize(new Dimension(300, 280));
        imageLabel.setHorizontalAlignment(JLabel.CENTER);

        JPanel leftPanel = new JPanel(new BorderLayout());
        leftPanel.add(frameListScrollPane, BorderLayout.CENTER);

        JPanel buttonsPanel = new JPanel(new GridLayout(2, 2, 0, 0));
        buttonsPanel.add(moveUpButton);
        buttonsPanel.add(moveDownButton);
        buttonsPanel.add(addFrameButton);
        buttonsPanel.add(removeFrameButton);

        leftPanel.add(buttonsPanel, BorderLayout.SOUTH);

        JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        bottomPanel.add(loadButton);
        bottomPanel.add(saveButton);
        bottomPanel.add(exitButton);

        JPanel mainPanel = new JPanel(new BorderLayout());
        mainPanel.add(imageLabel, BorderLayout.CENTER);
        mainPanel.add(bottomPanel, BorderLayout.SOUTH);

        add(leftPanel, BorderLayout.WEST);

        add(mainPanel, BorderLayout.CENTER);

        pack();
    }

    public Component getComponent(String name) {
        return components.get(name);
    }
}